package com.pd.backend.web.controller.logistics.transfer;

import com.pd.backend.common.PageResult;
import com.pd.backend.common.R;
import com.pd.backend.domain.dto.FleetDto;
import com.pd.backend.domain.pojo.Fleet;
import com.pd.backend.domain.pojo.Truck;
import com.pd.backend.domain.pojo.TruckDriver;
import com.pd.backend.domain.pojo.TruckType;
import com.pd.backend.service.logistics.TruckFleetService;
import com.pd.backend.service.logistics.TruckTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.temporal.TemporalField;
import java.util.List;

@RestController
@RequestMapping("/transfer/truck")
public class TruckController {

    @Autowired
    private TruckTypeService truckTypeService;

    @Autowired
    private TruckFleetService truckFleetService;


    /**
     * 车辆类型  多条件分页查询
     *
     * @param size            每页数据条数
     * @param current         当前页
     * @param allowableVolume 车辆载量
     * @param allowableLoad   车辆体积
     * @param name            车辆类型名称
     * @return
     */
    @GetMapping("/truck-type/page")
    public PageResult<TruckType> getPage(Integer size, Integer current, String allowableVolume, String allowableLoad, String name) {
        return truckTypeService.getPage(size, current, allowableVolume, allowableLoad, name);
    }

    /**
     * 新增车辆类型
     *
     * @param truckType
     * @return
     */
    @PostMapping("/truck-type")
    private R save(@RequestBody TruckType truckType) {
        return truckTypeService.save(truckType);
    }

    /**
     * 修改车辆类型
     *
     * @param truckType
     * @return
     */
    @PutMapping("/truck-type")
    public R modify(@RequestBody TruckType truckType) {
        return truckTypeService.modify(truckType);
    }

    /**
     * 删除车辆类型
     *
     * @param id
     * @return
     */
    @DeleteMapping("/truck-type/{id}")
    public R remove(@PathVariable("id") String id) {
        return truckTypeService.remove(id);
    }

    /**
     * 车队-多条件分页查询
     *
     * @param size        每页数据条数
     * @param current     当前页
     * @param manager     负责人
     * @param fleetNumber 车队编号
     * @param name        车队名称
     * @return
     */
    @GetMapping("/fleet/page")
    public PageResult<Fleet> getTruckFleetPage(Integer size, Integer current, String manager, String fleetNumber, String name) {
        return truckFleetService.getPage(size, current, manager, fleetNumber, name);
    }

    /**
     * 根据车队id分页查询车辆信息
     *
     * @param size    每页数据条数
     * @param current 当前页
     * @param fleetId 车队id
     * @return
     */
    @GetMapping("/fleet/getTruckList/page")
    public PageResult<Truck> getTruckList(Integer size, Integer current, String fleetId) {
        return truckFleetService.getTruckList(size, current, fleetId);
    }

    /**
     * 根据车队id分页查询司机信息
     *
     * @param size    每页数据条数
     * @param current 当前页
     * @param fleetId 车队id
     * @return
     */
    @GetMapping("/fleet/getDriverList/page")
    public PageResult<TruckDriver> getDriverList(Integer size, Integer current, String fleetId) {
        return truckFleetService.getDriverList(size, current, fleetId);
    }

    /**
     * 修改车队
     *
     * @param fleetDto
     * @return
     */
    @PutMapping("/fleet")
    public R modify(FleetDto fleetDto) {
        return truckFleetService.modify(fleetDto);
    }
}
